package com.fh.fruit.service.setMeal.impl;

import com.fh.dao.DaoSupport;
import com.fh.entity.Page;
import com.fh.fruit.service.setMeal.SetMealManager;
import com.fh.util.PageData;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

/**
 * @author 套餐service类
 */
@Service
public class SetMealService implements SetMealManager {
	  @Resource(name = "daoSupport")
	  private DaoSupport dao;

	@SuppressWarnings("unchecked")
	@Override
	public List<Map<String, Object>> getMealList(Page page) throws Exception {
		return (List<Map<String, Object>>) dao.findForList("SetMealMapper.getMeallistPage",page);
	}

	@SuppressWarnings("unchecked")
	@Override
	public Map<String, Object> getMealMsg(PageData pd) throws Exception {
		return (Map<String,Object>) dao.findForObject("SetMealMapper.getMealMsg", pd);
	}

	@Override
	public int saveMeal(PageData pd) throws Exception {
		int num=1;
		try{
			num=(int) dao.save("SetMealMapper.saveMeal", pd);
		} catch (Exception e) {
			e.printStackTrace();
			num=0;
			return num;
		}finally {
			if(num!=1){
				TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
			}
		}
			return num;
		}

	@Override
	public int updateMeal(PageData pd) throws Exception {
		int num =1;
		/*num=(int) dao.findForObject("SetMealMapper.getMealOrderNum", pd);
		if(num>0){
			num=2;
			return num;
		}*/
		num=(int) dao.update("SetMealMapper.updateMeal", pd);
		return num;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Map<String, Object>> getMealGoodsList(Page page) throws Exception {
		return (List<Map<String, Object>>) dao.findForList("SetMealMapper.getMealGoodslistPage",page);
	}

	@SuppressWarnings("unchecked")
	@Override
	public Map<String, Object> getMealGoods(PageData pd) throws Exception {
		return (Map<String,Object>) dao.findForObject("SetMealMapper.getMealGoods",pd);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Map<String, Object>> getGoodsSpecList(Page page) throws Exception {
		return (List<Map<String, Object>>) dao.findForList("SetMealMapper.getGoodsSpeclistPage",page);
	}

	@Override
	public int saveMealGoods(PageData pd) throws Exception {
		return (int)dao.save("SetMealMapper.saveMealGoods", pd);
	}

	@Override
	public int deleteMealGoods(PageData pd) throws Exception {
		return (int) dao.update("SetMealMapper.deleteMealGoods", pd);
	}

	@Override
	public int updateMealState(PageData pd) throws Exception {
		return (int) dao.update("SetMealMapper.updateMealState", pd);
	}

	@Override
	public int updateMealGoods(PageData pd) throws Exception {
		return (int) dao.update("SetMealMapper.updateMealGoods", pd);
	}

	@Override
	public int updateSaleState(PageData pd) throws Exception {
		return (int) dao.update("SetMealMapper.updateSaleState", pd);
	}
}
